package com.zhiyou100.video.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class HandleInterceptorAdmin implements HandlerInterceptor{

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		System.out.println("渲染已结束，准备返回给用户");
	}
	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		 System.out.println("控制器已处理完，即将要渲染");
	}
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
		HttpSession session = request.getSession();
		Object o = session.getAttribute("admin");
		if(o==null) {
			System.out.println("你还没有登陆，请返回");
			response.sendRedirect(request.getServletContext().getAttribute("BaseContext")+"");
		}else {
			System.out.println("管理员已登录");
			return true;
		}
		return false;
	}

}
